#!/bin/bash

# Slackware build script for jfsw_hires_pack

# Written by B. Watson (yalhcru@gmail.com)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# 20211030 bkw: update for v20201205_r21.
# - source is now made from upstream SVN, see svn2tarxz.sh.
# - HRP works with shareware .grp now, get rid of warning.
# - use correct homepage.
# - fix CRLF endings in docs.
# - add README note about the truncated sword.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=jfsw_hires_pack
VERSION=${VERSION:-20201205_r21}
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $PKG/usr/share/games $OUTPUT
cd $PKG/usr/share/games
tar xvf $CWD/$PRGNAM-$VERSION.tar.xz
mv $PRGNAM-$VERSION jfsw
cd jfsw
chown -R root:root .
find . -type f -exec chmod 644 {} \+
find . -type d -exec chmod 755 {} \+

rm -f *.bat

# jfsw will read <foo>.def whenever it loads <foo>.grp. it also
# always reads sw.def. so this seems to be the correct way to
# name these so they'll get auto-loaded.
mv tdragon.def td.def
mv wanton.def wd.def

# TODO: what about highres/skyboxes/Sky_Stars? Nothing in any of the
# .def files references it.

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
sed -i 's,\r,,' *.txt
mv *.txt $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
